package com.htfyun.unisound.serialmotor.fragment;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;

import com.htfyun.unisound.serialmotor.R;


/**
 * Created by sst on 2018/7/12.
 */

public class LedSelectedDialogFragment extends DialogFragment {
    private String title;

    private String[] items;

    private DialogInterface.OnMultiChoiceClickListener onMultiChoiceClickListener;

    private DialogInterface.OnClickListener positiveCallback;


    public void show(String title,
                     String[] items,
                     DialogInterface.OnMultiChoiceClickListener onMultiChoiceClickListener,
                     DialogInterface.OnClickListener positiveCallback,
                     FragmentManager fragmentManager) {
        this.title = title;
        this.items = items;
        this.onMultiChoiceClickListener = onMultiChoiceClickListener;
        this.positiveCallback = positiveCallback;
        show(fragmentManager, getClass().getSimpleName());
    }


    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.MyDialogTheme);;

        builder.setTitle(title)
                .setMultiChoiceItems(items, null, onMultiChoiceClickListener)
                .setPositiveButton(android.R.string.ok, positiveCallback);
        return builder.create();
    }
}
